<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<script type="text/javascript">
    function ajaxRequest() {
        var xmlHttpRequest = new XMLHttpRequest();
        // 发送ajax请求
        xmlHttpRequest.open("GET","http://localhost:8080/book/ajaxServlet?action=getAjax",true);
        xmlHttpRequest.onreadystatechange = function (){
            if (xmlHttpRequest.readyState == 4 && xmlHttpRequest.status == 200) {
                alert("收到服务器返回的数据：" + xmlHttpRequest.responseText);
                var jsonObj = xmlHttpRequest.responseText;
                document.getElementById("json").innerHTML = "编号：" + jsonObj.id + "用户名:" + jsonObj.username;
            }
        }
        xmlHttpRequest.send()
        alert("hello")
    }
</script>

<button onclick="ajaxRequest()">ajax request</button>
<div id="json">
</div>
</body>
</html>